home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Collections: Amiga Amateur Radio User Group
/
AARUG UK #20 (199x)(Amiga Amateur Radio User Group UK)(PD)[G4DCV].zip
/
AARUG UK #20 (199x)(Amiga Amateur Radio User Group UK)(PD)[G4DCV].adf
/
NCOMM
/
PbConvert.C
< prev
next >
Wrap
C/C++ Source or Header
|
1978-01-09
|
12KB
|
313 lines
/* PbConvert for use with NComm V1.9... */
/* Public Domain by Torkel Lodberg 1990 */
#include <stdio.h>
#include <exec/types.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/exec.h>
#include <fcntl.h>
#include <ctype.h>
#include <math.h>
#define OLD_FILETYPE_PHONE 5
#define NEW_FILETYPE_PHONE 6
static struct pb_Data2 { /* V1.8 file format ***/
UBYTE name[41];
UBYTE phone[61];
UBYTE comment[41];
UBYTE pass_word[30];
UBYTE script_file[33];
UBYTE config_file[33];
UBYTE dummy;
UBYTE char_set; /*** 0-11 ***/
UBYTE baud; /*** 0-6 ( 300 - 19200) ***/
UBYTE data_length; /*** 7 or 8 ***/
UBYTE parity; /*** None, odd, even ***/
UBYTE stop_bits; /*** 1 - 2 ***/
UBYTE duplex; /*** Full - half ***/
};
static struct pb_Data { /*** V1.9-> file format ***/
UBYTE name[41];
UBYTE phone[61];
UBYTE comment[41];
UBYTE pass_word[30];
UBYTE script_file[33];
UBYTE config_file[33];
UBYTE macro_file[33];
UBYTE char_set; /*** 0-11 ***/
UBYTE baud; /*** 0-6 ( 300 - 19200) ***/
UBYTE data_length; /*** 7 or 8 ***/
UBYTE parity; /*** None, odd, even ***/
UBYTE stop_bits; /*** 1 - 2 ***/
UBYTE duplex; /*** Full - half ***/
UBYTE future[64];
};
static int fd = NULL; /* File handles */
static int fe = NULL;
int wb_open; /* Started from workbench? */
void cleanup(text) /* Exit program cleanly */
char *text;
{
if (wb_open) printf("\n");
if (text) printf("%s\n",text);
if (fd > 0) close(fd);
if (fe > 0) close(fe);
if (wb_open) Delay(100);
exit(0);
}
void brk() /* Called by every CTRL-C / D keypress */
{
printf("*** BREAK\n");
cleanup(NULL);
}
void main(argc, argv) /* Main program */
int argc;
char *argv[];
{
int status, i;
char ch;
struct pb_Data data;
struct pb_Data2 data2;
char answer [256];
char infile [256];
char outfile [256];
int baudchange = NULL;
int datachange = NULL;
int paritychange = NULL;
int stopchange = NULL;
int oldformat = NULL, removeit = NULL;
int baud, data_length, parity, stop_bits;
if (!argc) wb_open = TRUE;
else wb_open = FALSE;
if (onbreak(&brk)) cleanup(NULL);
chkabort();
if (argc < 3) {
printf("PbConvert for use with NComm V1.9. May remove passwords\n");
printf("and filenames from phonebooks, as well as converting the\n");
printf("NComm V1.8 file format. Optional global serial changes.\n");
printf("Public Domain by Torkel Lodberg 1990\n\n");
if (argc) {
printf(" Usage: PbConvert <infile> <outfile> [-b] [-d] [-p] [-s] [-r] [-e]\n");
printf(" Options: [-b]xxxxx where xxxxx is the baudrate (300-19200)\n");
printf(" [-d]x where x is the data length (7-8)\n");
printf(" [-p]x where x is the parity (n)one, (o)dd, (e)ven\n");
printf(" [-s]x where x is the number of stop bits (1-2)\n");
printf(" [-r]emove filenames and passwords\n");
printf(" [-e]xpect input file to be of old format (v1.8)\n\n");
cleanup(NULL);
}
}
if (argc) {
strcpy(infile, argv[1]);
strcpy(outfile, argv[2]);
for (i = 3; i < argc; i++) {
if (!strncmp(argv[i], "-b", 2)) {
baudchange = TRUE;
switch (atoi(&argv[i][2])) {
case 300: baud = 0; break;
case 600: baud = 1; break;
case 1200: baud = 2; break;
case 2400: baud = 3; break;
case 4800: baud = 4; break;
case 9600: baud = 5; break;
case 19200: baud = 6; break;
default: cleanup("Invalid baud rate!");
}
}
if (!strncmp(argv[i], "-d", 2)) {
datachange = TRUE;
switch (atoi(&argv[i][2])) {
case 8: data_length = 0; break;
case 7: data_length = 1; break;
default: cleanup("Invalid data length!");
}
}
if (!strncmp(argv[i], "-p", 2)) {
paritychange = TRUE;
switch (toupper(argv[i][2])) {
case 'N': parity = 0; break;
case 'O': parity = 1; break;
case 'E': parity = 2; break;
default: cleanup("Invalid parity!");
}
}
if (!strncmp(argv[i], "-s", 2)) {
stopchange = TRUE;
switch (atoi(&argv[i][2])) {
case 1: stop_bits = 0; break;
case 2: stop_bits = 1; break;
default: cleanup("Invalid number of stop bits!");
}
}
if (!strncmp(argv[i], "-r", 2)) {
removeit = TRUE;
}
if (!strncmp(argv[i], "-e", 2)) {
oldformat = TRUE;
}
}
} else {
strcpy(infile, "NComm:NComm.phone");
strcpy(outfile, "RAM:NComm.phone");
printf("Enter name of phonebook input file (Enter=NComm:NComm.phone): ");
gets(answer);
if (strlen(answer)) strcpy(infile, answer);
printf("Enter name of phonebook output file (Enter=RAM:NComm.phone): ");
gets(answer);
if (strlen(answer)) strcpy(outfile, answer);
oldformat = TRUE;
printf("\nExpect old file format (Enter=Yes): ");
gets(answer);
if (toupper(answer[0]) == 'N') oldformat = FALSE;
printf("\nNew baud rate (Enter=No Change): ");
gets(answer);
if (strlen(answer)) {
baudchange = TRUE;
switch (atoi(answer)) {
case 300: baud = 0; break;
case 600: baud = 1; break;
case 1200: baud = 2; break;
case 2400: baud = 3; break;
case 4800: baud = 4; break;
case 9600: baud = 5; break;
case 19200: baud = 6; break;
default: cleanup("Invalid baud rate!");
}
}
printf("New data length (Enter=No Change): ");
gets(answer);
if (strlen(answer)) {
datachange = TRUE;
switch (atoi(answer)) {
case 8: data_length = 0; break;
case 7: data_length = 1; break;
default: cleanup("Invalid data length!");
}
}
printf("New parity (Enter=No Change): ");
gets(answer);
if (strlen(answer)) {
paritychange = TRUE;
switch (toupper(answer[0])) {
case 'N': parity = 0; break;
case 'O': parity = 1; break;
case 'E': parity = 2; break;
default: cleanup("Invalid parity!");
}
}
printf("New number of stop bits (Enter=No Change): ");
gets(answer);
if (strlen(answer)) {
stopchange = TRUE;
switch (atoi(answer)) {
case 1: stop_bits = 0; break;
case 2: stop_bits = 1; break;
default: cleanup("Invalid number of stop bits!");
}
}
removeit = FALSE;
printf("\nRemove filenames and passwords (Enter=No): ");
gets(answer);
if (toupper(answer[0] == 'Y')) removeit = TRUE;
}
if((fd = open(infile, O_RDONLY, NULL)) == -1
||read (fd, &ch, 1) != 1)
if (argc) cleanup("Cannot open data-file");
if (oldformat) {
if (ch != OLD_FILETYPE_PHONE)
cleanup("Error reading NComm.phone: Illegal file type");
ch = NEW_FILETYPE_PHONE;
} else {
if (ch != NEW_FILETYPE_PHONE)
cleanup("Error reading NComm.phone: Illegal file type");
}
if((fe = open(outfile, O_RDWR|O_CREAT|O_TRUNC, NULL)) == -1)
cleanup("Cannot create file!");
write (fe, &ch, 1);
if (oldformat) {
while((status = read(fd, (char *) &data2, sizeof(struct pb_Data2))) == sizeof(struct pb_Data2)) {
if (removeit) {
memset(data2.pass_word, 0, sizeof(data2.pass_word));
memset(data2.script_file, 0, sizeof(data2.script_file));
memset(data2.config_file, 0, sizeof(data2.config_file));
}
if (baudchange) data2.baud = baud;
if (datachange) data2.data_length = data_length;
if (paritychange) data2.parity = parity;
if (stopchange) data2.stop_bits = stop_bits;
strcpy(data.name, data2.name);
strcpy(data.phone, data2.phone);
strcpy(data.comment, data2.comment);
strcpy(data.pass_word, data2.pass_word);
strcpy(data.script_file, data2.script_file);
strcpy(data.config_file, data2.config_file);
memset(data.macro_file, 0, sizeof(data.macro_file));
data.char_set = data2.char_set;
data.baud = data2.baud;
data.data_length = data2.data_length;
data.parity = data2.parity;
data.stop_bits = data2.stop_bits;
data.duplex = data2.duplex;
memset(data.future, 0, sizeof(data.future));
status = write(fe, (char *) &data, sizeof(struct pb_Data));
if(status != sizeof(struct pb_Data))
cleanup("Error while writing!");
}
} else {
while((status = read(fd, (char *) &data, sizeof(struct pb_Data))) == sizeof(struct pb_Data)) {
if (removeit) {
memset(data.pass_word, 0, sizeof(data.pass_word));
memset(data.script_file, 0, sizeof(data.script_file));
memset(data.config_file, 0, sizeof(data.config_file));
memset(data.macro_file, 0, sizeof(data.macro_file));
}
if (baudchange) data.baud = baud;
if (datachange) data.data_length = data_length;
if (paritychange) data.parity = parity;
if (stopchange) data.stop_bits = stop_bits;
status = write(fe, (char *) &data, sizeof(struct pb_Data));
if(status != sizeof(struct pb_Data))
cleanup("Error while writing!");
}
}
cleanup(NULL);
}